/**
 * 文件api
 */
import { DeleteRequestApi, PostRequestApi } from '@/utils/api/RequestApi'

export const FILE_API_PRE_PREFIX = '/file/'

/**
 * 单文件上传
 * @param data
 */
export function fileUpload(data: FormData) {
  return new PostRequestApi(FILE_API_PRE_PREFIX + 'fileUpload', data).get()
}

/**
 * 多文件上传
 * @param data
 */
export function multipartFileUpload(data: FormData) {
  return new PostRequestApi(FILE_API_PRE_PREFIX + 'multipartFileUpload', data).get()
}

/**
 * 文件删除
 * @param id 文件id
 */
export function deleteFile(id: string) {
  return new DeleteRequestApi(
    FILE_API_PRE_PREFIX + 'delete/' + id,
    {},
    {
      headers: {
        'content-type': 'application/x-www-form-urlencoded',
      },
    },
  ).get()
}

/**
 * 文件删除(url删除)
 * @param url 文件url
 */
export function deleteFileByUrl(url: string) {
  return new PostRequestApi(FILE_API_PRE_PREFIX + 'delete/url', {
    url: url,
  }).get()
}
